<h1>
    <?=$this->title ?>
</h1>
<?
    if (!$this->is_add) // Edit Mode
    {
?>
<div id="right_menu">
    <ul>
<?
        $i = 0;
        foreach ($this->menu as $title => $action)
        {
            $i++;
            $container = ($action == 'edit' || $action == 'delete') ? 'inner' : 'container';
?>
        <li
<?
            if ($this->action == $action)
                echo "class=\"active\"";
?>
        >

        <a href="#"
<?
            if ($action == 'delete')
            {
?>
                onClick="if(confirm('Sure?')) {ajaxViewByCompany({id: <?=$this->model_company->getID() ?>,
                                                                action: '<?=$action ?>',
                                                                container: '<?=$container ?>',
                                                                parent_id: <?=$this->model_company->getOwnerPoolID() ?>}); return false;};"
<?
            }
            else
            {
?>
                onClick="ajaxViewByCompany({id: <?=$this->model_company->getID(); ?>,
                                          action: '<?=$action ?>',
                                          container: '<?=$container ?>',
                                          no_apply: true}); return false;"
<?
            };
?>              ><?=$title.(($action == "delete") ? ($this->model_company->isPool() ? "pool" : "company") : "") ?></a>
	</li>
<?
        };
?>
	</ul>
</div>
<?
    }; //if (!$this->is_add)
?>

<div id="container" <? if ($this->is_add) echo "style=\"margin-top: -50px;\""; ?>>
    <div>
<?
    Principio_Library_Common::printErrorsAndMsg();
?>
        <table class="form_table">
            <tr>
                <td class="title">Caption:</td>
                <td class="input_field">
                    <input type="text" name="caption" id="caption" value="<?=$this->model_company->getCaption(); ?>" />
                </td>
                <td class="description"></td>
            </tr>
            <tr>
                <td class="title">Type:</td>
                <td class="input_field">
                    <select name="type" id="company_type" onchange="event_onChangeCompanyType();" >
                        <? if (!$this->has_ancestors) { ?><option value="1" <? if ($this->model_company->isCompanyNotInPool()) echo "selected"; ?>>Company</option><? }; ?>
                        <option value="2" <? if ($this->model_company->isPool()) echo "selected"; ?>>Pool</option>
                        <? if (!$this->has_ancestors) { ?><option value="3" <? if ($this->model_company->isCompanyInPool()) echo "selected"; ?>>Company in an existing pool</option><? }; ?>
                    </select>
                </td>
                <td class="description">
<?
    if ( ($this->has_ancestors))
        echo "You can't change type of this Pool because of it isn't empty";
?>
                </td>
            </tr>
            <tr  <?=( ($this->model_company->isCompanyInPool()) ? "" : "style=\"display: none;\"") ?> id="tr_select_pool">
                <td class="title">Select Pool:</td>
                <td class="input_field">
                    <select name="pool" id="pool" onchange="event_onChangePool();">
                        <option value="0">---Select: ---</option>
<?
    $pool_ip = "-1";
    foreach ($this->pools as $model_pool)
    {
?>
                        <option value="<?=$model_pool->getId() ?>" <? if ($this->model_company->getOwnerPoolId() == $model_pool->getId()) { echo "selected "; $pool_ip = $model_pool->getIp(); };?>><?=$model_pool->getCaption(); ?></option>
<?
    };
?>
                    </select>
                </td>
                <td class="column3"></td>
            </tr>
            <tr <?=(($this->model_company->isCompanyInPool()) ? "" : "style=\"display: none;\"") ?> id="tr_ip_rd">
                <td class="title">IP/Mask:</td>
                <td class="input_field">
                    <input type="text" name="type_3_ip" id="ip_rd" value="<? if ($pool_ip != "-1") echo $pool_ip; ?>" readonly="readonly" />
                </td>
                <td></td>
            </tr>
            <tr id="tr_proxy">
                <td class="title">Proxy:</td>
                <td class="input_field">
                    <input type="text" name="proxy" id="proxy" value="<?=$this->model_company->getProxy();?>" />
                </td>
                <td class="description"></td>
            </tr>
            <tr <?=( (!$this->model_company->isCompanyInPool()) ? "" : "style=\"display: none;\"") ?> id="tr_ip">
                <td class="title">IP/Mask:</td>
                <td class="input_field">
                    <input type="text" name="ip" id="ip" value="<?=$this->model_company->getIP(); ?>" />
                </td>
                <td class="description">xxx.xxx.xxx.xxx/xxx OR xxx.xxx.xxx.xxx/xxx.xxx.xxx.xxx</td>
            </tr>
            <tr id="tr_vlan_id">
                <td class="title">VLAN ID:</td>
                <td class="input_field">
                    <input class="input_text" type="text" name="vlan" id="vlan" value="<?=($this->model_company->getVlanID() != -1 ? $this->model_company->getVlanID() : "") ?>" />
                </td>
                <td class="description">Leave blank to disable.</td>
            </tr>
            <tr id="tr_vlan_pc_id">
                <td class="title">PC VLAN ID:</td>
                <td class="input_field">
                    <input name="vlan_pc" id="vlan_pc" value="<?=($this->model_company->getVlanPcID() != -1 ? $this->model_company->getVlanPcID() : "") ?>" />
                </td>
                <td class="description">Leave blank to disable. Won't work without VLAN ID!</td>
            </tr>
        </table>
        <table border="0" width="100%" class="buttons">
            <tr>
                <td align="right">
                    <input class="save" type="submit" name="apply" value="<?=($this->is_add ? "Add Company" : "Apply changes") ?>"
                           onClick="ajaxViewByCompany({container: 'inner', action: '<?=($this->is_add ? "add" : "edit") ?>', parent_id: <?=($this->model_company->isCompanyInPool() ? $this->model_company->getOwnerPoolID() : "-1") ?> <? if (!$this->is_add) echo ", id: ".$this->model_company->getID() ?>});"/>
                    <input class="cancel" type="submit" name="reset" value="Reset" onClick="<?=($this->is_add ? "addItem({menu: 'viewbycompany', container: 'inner'".($this->model_company->isCompanyInPool() ? (", pool_id: ".$this->model_company->getOwnerPoolID()) : "")."}); return false;" : "ajaxViewByCompany({id: ".$this->model_company->getID().", action: 'edit', container: 'inner', no_apply: true}); return false;" ) ?>"/>
                </td>
            </tr>
        </table>
    </div>
</div>